﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI;
using AjaxControlToolkit;
using System.Xml.Serialization;
using System.ComponentModel;

namespace WebPartExtenderToolkit
{

    [ToolboxData("<{0}:PopOutWebPart runat=server></{0}:ResizableWebPart>")]
    [XmlRoot(Namespace = "PopOutWebPart")]
    public class PopOutWebPart : ExtenderWebPartBase
    {

        protected override void CreateChildControls()
        {            
            base.CreateChildControls();
            Controls.Add(new LiteralControl("body"));
            ChildControlsCreated = true;
        }

        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);
            //extender.TargetControlID = this.TargetControlID;
            //extender.Enabled = Enabled && !string.IsNullOrEmpty(TargetControlID);
            //extender.BehaviorID = this.BehaviorID;
            //extender.ID = this.ID + "PopOutExtender";

            var target =
                from WebPart w in WebPartManager.GetCurrentWebPartManager(Page).WebParts
                where (w.ID == this.TargetControlID)
                select w;

            foreach(WebPart wp in target)
            {
                wp.Style.Add("border", "2px solid green");
            }
            

            //Always hide the extender control chrome, because it'll show up as an empty webpart
            ChromeType = PartChromeType.None;
            Title = "Pop Out WebPart Extender";
        }

        void wp_PreRender(object sender, EventArgs e)
        {
            WebPart me = sender as WebPart;
        }

    }
}
